<?php

class Controller_Public extends FLEA_Controller_Action
{	

	function Controller_Public()
    {
        
		
	}

	function getTemplates()
	{
		$controller = isset($_GET['controller']) ? $_GET['controller'] : 'default';
		$action = isset($_GET['action']) ? $_GET['action'] : 'index';
		
		return $controller.'_'.$action.'.html';
	}

	function getMenuName()
	{
		$tableMenu = &get_singleton('Model_Menus');
		
		$controller = $_GET['controller'];
		$action = $_GET['action'];

		$conditions = 'menu_controller = \''.$controller.' \' AND menu_action = \''.$action.'\'';
		$menu = $tableMenu->find($conditions);
		return $menu['menu_name'];
	}


	
	/**
     * 返回用 _setBack() 设置的 URL
     */
    function _goBack() {
        $url = $this->_getBack();
        unset($_SESSION['BACKURL']);
        redirect($url);
    }

    /**
     * 设置返回点 URL，稍后可以用 _goBack() 返回
     */
    function _setBack() {
        $_SESSION['BACKURL'] = encode_url_args($_GET);
    }

    /**
     * 获取返回点 URL
     *
     * @return string
     */
    function _getBack() {
        if (isset($_SESSION['BACKURL'])) {
            $url = $this->rawurl($_SESSION['BACKURL']);
        } else {
            $url = $this->_url();
        }
        return $url;
    }
		
	function rawurl($queryString) {
    	if (substr($queryString, 0, 1) == '?') {
    		$queryString = substr($queryString, 1);
    	}
    	return $_SERVER['SCRIPT_NAME'] . '?' . $queryString;
    }
} 